package edu.gyc.hiseckill.controller;


import edu.gyc.hiseckill.error.BusinessErrorEnum;
import edu.gyc.hiseckill.error.BusinessException;
import edu.gyc.hiseckill.model.CommonReturnType;
import edu.gyc.hiseckill.model.Item;
import edu.gyc.hiseckill.model.ItemStock;
import edu.gyc.hiseckill.model.Promo;
import edu.gyc.hiseckill.service.ItemService;
import edu.gyc.hiseckill.service.ItemStockService;
import edu.gyc.hiseckill.service.PromoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *
 *
 *
 *  前端控制器
 * </p>
 *
 * @author ls
 * @since 2020-01-23
 */
@RestController
@RequestMapping("/item")
@CrossOrigin(allowCredentials="true",allowedHeaders = "*")
public class ItemController {

    @Autowired
    private ItemService itemService;
    @Autowired
    private ItemStockService itemStockService;
    @Autowired
    private PromoService promoService;

    @RequestMapping("/addItem")
    public CommonReturnType creatItem(Item item) throws BusinessException {
        Item fullItem = itemService.createItem(item);
        return CommonReturnType.create(fullItem);
    }

    @RequestMapping("/getItem")
    public CommonReturnType getItem(Integer id) throws BusinessException {
        Item item = itemService.getItem(id);
        return CommonReturnType.create(item);
    }

    @RequestMapping("/listItem")
    public CommonReturnType listItem() throws BusinessException {

        return CommonReturnType.create(itemService.listItem());
    }
}

